home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tricks of the Mac Game Programming Gurus
/
TricksOfTheMacGameProgrammingGurus.iso
/
More Source
/
C⁄C++
/
Swar
/
main.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-08-21
|
4KB
|
206 lines
#include "swar.h"
#include "globals.h"
main()
{
short tics;
MaxApplZone();
ToolBoxInit();
GetDateTime((unsigned long *)&randSeed);
DrawMenuBar();
WindowInit();
gDone = FALSE;
gPlaying = FALSE;
gPauseOn = FALSE;
gSoundOn = TRUE;
gSndIsInitted = FALSE;
SetChecks();
LoadPieces();
LoadSounds();
InitColors();
wneAvail = FALSE;
SysEnvirons(1, &theSysEnv);
if (theSysEnv.machineType >= 1) {
if (NGetTrapAddress(0xA860, 1) != 0xA89F)
wneAvail = TRUE;
} /* if */
while (!gDone) {
if (gPlaying && !gPauseOn) {
GameCycle();
} /* if */
HandleEvent();
} /* while */
ExitAppl();
} /* main () */
HandleEvent()
{
char theChar;
if (!wneAvail) {
GetNextEvent(everyEvent, &gTheEvent);
SystemTask();
} /* if */
else
WaitNextEvent(everyEvent, &gTheEvent, 0L, 0L);
switch (gTheEvent.what) {
case mouseDown:
if ((gPauseOn && gPlaying) || !gPlaying)
HandleMouseDown();
break;
case keyDown:
case autoKey:
theChar = gTheEvent.message & charCodeMask;
if ((gTheEvent.modifiers & cmdKey) != 0)
HandleMenuChoice(MenuKey(theChar));
break;
case updateEvt:
case nullEvent:
case mouseUp:
case keyUp:
case diskEvt:
case activateEvt:
case networkEvt:
case driverEvt:
case app1Evt:
case app2Evt:
case app3Evt:
break;
case app4Evt:
break;
default:
break;
} /* switch */
} /* HandleEvent() */
HandleMouseDown()
{
WindowPtr whichWindow;
short int thePart;
long int menuChoice, windSize;
thePart = FindWindow(gTheEvent.where, &whichWindow);
switch (thePart) {
case inMenuBar:
menuChoice = MenuSelect(gTheEvent.where);
HandleMenuChoice(menuChoice);
break;
case inSysWindow:
SystemClick(&gTheEvent, whichWindow);
break;
case inDrag:
// DragWindow(whichWindow, gTheEvent.where, &gDragRect);
break;
case inGoAway:
// gDone = TRUE;
break;
case inContent:
case inGrow:
case inZoomIn:
case inZoomOut:
default:
break;
} /* switch */
} /* HandleMouseDown() */
HandleMenuChoice(menuChoice)
long int menuChoice;
{
int theMenu;
int theItem;
if (menuChoice != 0) {
theMenu = HiWord(menuChoice);
theItem = LoWord(menuChoice);
switch (theMenu) {
case 500:
HandleAppleChoice(theItem);
break;
case 501:
HandleFileChoice(theItem);
break;
} /* switch */
HiliteMenu(0);
} /* if */
} /* HandleMenuChoice() */
HandleAppleChoice(theItem)
int theItem;
{
Str255 accName;
int accNumber;
GrafPtr savePort;
switch (theItem) {
case 1:
break;
default:
GetPort(&savePort);
GetItem(gAppleMenu, theItem, accName);
accNumber = OpenDeskAcc(accName);
SetPort(savePort);
break;
} /* switch */
} /* HandleAppleChoice() */
HandleFileChoice(theItem)
int theItem;
{
GrafPtr savePort;
switch (theItem) {
case 1:
EnableItem (gFileMenu, 2);
EnableItem (gFileMenu, 5);
gPlaying = TRUE;
gPauseOn = FALSE;
InitGame();
HideCursor();
GetPort(&savePort);
SetPort((GrafPtr)gPictureWindow);
ShowWindow((WindowPtr)gPictureWindow);
//
// Must set FG and BG pens for CopyBits to work
//
RGBForeColor(&myBlack);
RGBBackColor(&myWhite);
break;
case 2:
if (gPauseOn) {
gPauseOn = FALSE;
HideCursor();
} /* if */
else {
gPauseOn = TRUE;
ShowCursor();
} /* else */
SetChecks();
break;
case 3:
if (gSoundOn)
gSoundOn = FALSE;
else
gSoundOn = TRUE;
SetChecks();
break;
case 5:
break;
case 7:
gDone = TRUE;
EnableItem (gFileMenu, theItem);
DisableItem (gFileMenu, 2);
DisableItem (gFileMenu, 5);
break;
} /* switch */
} /* HandleFileChoice() */